package cn.edu.hunau.java.week03.day02;

import com.sun.net.httpserver.Filter;

import java.util.ArrayList;
import java.util.List;

public class FilterApple {
    public static List<Apple> filterByColor(List<Apple> datas, String color){
        List<Apple> result=new ArrayList<>();
        for(Apple apple:datas){
            if(color.equals(apple.getColor())){
                result.add(apple);
            }
        }
        return result;
    }

    public static List<Apple> filterByType(List<Apple> datas,String type){
        List<Apple> result=new ArrayList<>();
        for(Apple apple:datas){
            if(type.equals(apple.getType())){
                result.add(apple);
            }
        }
        return result;
    }

    public static List<Apple> filterByWeight(List<Apple> datas,double weight){
        List<Apple> result=new ArrayList<>();
        for(Apple apple:datas){
            if(weight<=apple.getWeight()){
                result.add(apple);
            }
        }
        return result;
    }

    public static List<Apple> filter(List<Apple> datas, Filter filter){
        List<Apple> result=new ArrayList<>();
        for(Apple apple:datas){
            if(Boolean.parseBoolean(filter.toString())){
                result.add(apple);
            }
        }
        return result;
    }
}
